
def main():
    # 条件语句 if-elif-else
    x = 10
    if x < 0:
        print("x 是负数")
    elif x == 0:
        print("x 是零")
    else:
        print("x 是正数")

    # 循环语句 for 循环
    print("\nFor 循环示例:")
    for i in range(5):
        print(i)

    # 循环语句 while 循环
    print("\nWhile 循环示例:")
    count = 0
    while count < 5:
        print(count)
        count += 1

    # 循环控制语句 break, continue, pass
    print("\n循环控制语句示例:")

    # break 语句示例
    print("\nBreak 示例:")
    for i in range(10):
        if i == 5:
            break  # 退出循环
        print(i)

    # continue 语句示例
    print("\nContinue 示例:")
    for i in range(10):
        if i % 2 == 0:
            continue  # 跳过当前循环的剩余部分，继续下一次循环
        print(i)

    # pass 语句示例
    print("\nPass 示例:")
    for i in range(5):
        if i == 2:
            pass  # 占位符，不执行任何操作
        print(i)

    # 异常处理 try-except-finally
    print("\n异常处理示例:")
    try:
        a = int(input("请输入一个数字: "))
        b = int(input("请输入另一个数字: "))
        result = a / b
        print(f"{a} 除以 {b} 的结果是 {result}")
    except ValueError:
        print("错误：输入无效，请输入一个数字。")
    except ZeroDivisionError:
        print("错误：不能除以零。")
    finally:
        print("这个块总是会执行。")



if __name__ == "__main__":
    main()
